package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    PermissionService permissionService;
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        log.debug("PermissionController:  add");
        permissionService.add(permission);
        log.debug("权限添加成功");
        return new Result(true, "新增权限成功");
    }


    //分页查询
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        log.debug("PermissionController:  findByPage");
        PageResult pageResult= permissionService.findByPage(queryPageBean);
        log.debug("权限分页查询成功");
        return new Result(true,"权限分页查询成功",pageResult);
    }

    //删除
    @RequestMapping("/delById")
    public Result delById(Integer id){
        log.debug("PermissionController:  delById");
        permissionService.delById(id);
        log.debug("权限删除成功");
        return new Result(true,"权限根据id删除成功");
    }

    //编辑回显数据
    @RequestMapping("/findById")
    public Result findById(Integer id){
        log.debug("PermissionController:  findById");
        Permission permission= permissionService.findById(id);
        return new Result(true,"编辑回显成功",permission);
    }

    //编辑确定
    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission){
        log.debug("PermissionController:  edit");
        permissionService.edit(permission);
        log.debug("权限修改成功");
        return new Result(true, "修改权限成功");
    }
}
